@echo off

path=e:\masm32\nasm;E:\Mingw64\bin;e:\cygwin\bin;c:\programming\snsos\tools

del mbr.bin
del boot.bin
del kernel.o
del console.o
del memory.o
del kernel.exe
del kerneldata.bin
del kernel.bin
del diskdata.bin
del disk.bin
REM del disk.vhd

makembr ntmbr.bin mbr.bin 128 237 1 255

nasm boot.asm -o boot.bin
if errorlevel 1 goto end

x86_64-w64-mingw32-gcc.exe -masm=intel -m64 -std=c99 -nostdinc -c console.c memory.c kernel.c
if errorlevel 1 goto end

x86_64-w64-mingw32-ld.exe -nostdlib -static -e __main -Ttext 0x100000 kernel.o console.o memory.o -o kernel.exe 
if errorlevel 1 goto end

x86_64-w64-mingw32-objcopy.exe --remove-section=.idata -O binary kernel.exe kerneldata.bin
if errorlevel 1 goto end

REM disasm32-1.7.30.exe -b64 kerneldata.bin 100000 > kernel_disasm.asm

padbin kerneldata.bin kernel.bin 131072

cat mbr.bin boot.bin kernel.bin > diskdata.bin

padbin diskdata.bin disk.bin 1048576

REM bin2vhd disk.bin

e:
cd\program files\qemu
qemu-system-x86_64.exe -L . -m 256 -hda c:\programming\snsos\kernel\disk.bin -soundhw all -localtime -M pc -smp 4 -net nic -net nic
if errorlevel 1 goto end

exit

:end
pause